//
//  SimpleInputVC.m
//  MyProject
//
//  Created by 石小强 on 2018/4/25.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "SimpleInputVC.h"

@interface SimpleInputVC ()

@end

@implementation SimpleInputVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 96B3BC
    // 42CDD9
    [self setupNav];
    [self setupSubViews];
}

- (void)setupNav {
    CGSize saveBtnS = [Tool sizeWithText:@"保存" font:[UIFont fontWithName:@"PingFangSC-Regular" size:14]];
    UIButton *saveB = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, saveBtnS.width, 44)];
    [saveB setTitleColor:UIColorFromRGB(0x474C4D) forState:UIControlStateNormal];
    [saveB.titleLabel setFont:[UIFont fontWithName:@"PingFangSC-Regular" size:14]];
    [saveB setTitle:@"保存" forState:UIControlStateNormal];
    [saveB addTarget:self action:@selector(saveBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:saveB];
}

- (void)saveBtnClick {
    if (self.index == 1) {
        if (!self.textField.text || self.textField.text.length == 0) {
            [CommonUtils showToast:@"请输入职位名称"];
            return;
        }
        self.saveBlock(self.textField.text);
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        if (!self.textField.text || self.textField.text.length == 0) {
            [CommonUtils showToast:@"请输入邮箱"];
            return;
        }
        self.saveBlock(self.textField.text);
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)setupSubViews {
    if (self.index == 1) {
        self.navigationItem.title = @"职位名称";
        self.textField.placeholder = @"请输入职位名称";
        self.tipL.hidden = YES;
    } else {
        self.navigationItem.title = @"邮箱";
        self.textField.placeholder = @"请输入邮箱";
        self.tipL.hidden = NO;
    }
    [self.textField addTarget:self action:@selector(textFieldTextChange) forControlEvents:UIControlEventEditingChanged];
}

#pragma mark - UITextFieldDelegate
- (void)textFieldTextChange {
    NSLog(@"textFieldTextChange-----%@", self.textField.text);
    self.wordsNumberL.text = [NSString stringWithFormat:@"%zd/12", self.textField.text.length];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *result = [NSString stringWithFormat:@"%@%@", textField.text, string];
    if (result.length > 12) {
        [CommonUtils showToast:@"最多输入12个字符"];
        return NO;
    }
    return YES;
}

@end
